/*
 * Copyright (c) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import 'package:flutter/material.dart';
import 'package:ohfeature_sample/knock_share/utils/knock_enums.dart';
import '../../constants/share_constants.dart';

// 碰一碰三种场景的图片布局
class ImageContentWidget extends StatefulWidget {
  final LayoutEnum type;
  const ImageContentWidget({super.key, required this.type});

  @override
  State<ImageContentWidget> createState() => _ImageContentWidgetState();
}

class _ImageContentWidgetState extends State<ImageContentWidget> {
  @override
  Widget build(BuildContext context) {
    return _buildImageContent();
  }

  Widget _buildImageContent() {
    double width = MediaQuery.of(context).size.width - 32 > 400
        ? 400
        : MediaQuery.of(context).size.width - 32;
    return Container(
      margin: const EdgeInsets.symmetric(vertical: 16),
      alignment: Alignment.center,
      width: width,
      padding: const EdgeInsets.all(16),
      decoration: BoxDecoration(
          color: Colors.white, borderRadius: BorderRadius.circular(16)),
      child: widget.type == LayoutEnum.split
          ? Column(
              children: [
                ClipRRect(
                  borderRadius: BorderRadius.circular(16),
                  child: Image.asset(
                    'lib/assets/images/nfc_share_full.png',
                    width: width,
                    fit: BoxFit.fitWidth,
                  ),
                ),
                Container(
                  margin: const EdgeInsets.only(top: 16, left: 16, right: 16),
                  child: const Text(
                    ShareConstants.TITLE,
                    style: TextStyle(
                        fontSize: 16, color: Color.fromRGBO(0, 0, 0, 0.9)),
                  ),
                )
              ],
            )
          : Stack(
              alignment: AlignmentDirectional.bottomCenter,
              children: [
                Center(
                  child: ClipRRect(
                    borderRadius: BorderRadius.circular(16),
                    child: Image.asset(
                      'lib/assets/images/nfc_share_full.png',
                      width: width,
                      fit: BoxFit.fitWidth,
                    ),
                  ),
                ),
                Offstage(
                  offstage: widget.type == LayoutEnum.gallery ? true : false,
                  child: Container(
                    padding:
                        const EdgeInsets.only(left: 12, right: 12, bottom: 24),
                    child: const Text(ShareConstants.TITLE,
                        style: TextStyle(fontSize: 16, color: Colors.white)),
                  ),
                )
              ],
            ),
    );
  }
}
